package com.kaopu.sns.serviceimpl;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import sun.security.provider.MD5;

import com.kaopu.sns.service.RssService;
import com.sql.weeego.bean.base.UchomeBlog;
import com.sql.weeego.bean.base.UchomeBlogfield;
import com.sql.weeego.bean.base.kaopuIncludeBlog;
import com.sun.syndication.io.FeedException;
import com.weeego.util.net.Rss;
import com.weeego.util.string.Md5;
import com.weeego.web.base.BaseServiceImpl;

public class RssServiceImpl extends BaseServiceImpl implements RssService {

	public int saveBlog(int blog, String blogname, int uid, String username) {

		int i = 0;
		return i;
		// String rss = "";
		//
		// if (blog == 1) {
		// rss = "http://" + blogname + ".popo.blog.163.com/rss/";
		// } else if (blog == 2) {
		// rss = "http://blog.sina.com.cn/rss/" + blogname + ".xml";
		// } else if (blog == 3) {
		// rss = "http://" + blogname + ".blogspot.com/rss.xml";
		// } else if (blog == 4) {
		// rss = "http://feeds.qzone.qq.com/cgi-bin/cgi_rss_out?uin="
		// + blogname;
		// } else {
		// return 0;
		// }
		//
		//	

	}

	public int saveQqBlog(int blog, String blogname, int uid, String username) {

		String rss = "";

		if (username == "" || username == null) {
			return 0;
		}
		int __re = 0;
		rss = "http://feeds.qzone.qq.com/cgi-bin/cgi_rss_out?uin=" + blogname;

		List _rs = new ArrayList();
		try {
			_rs = Rss.parseRss(rss);
			if (_rs != null)
				try {
					{
						for (int i = 0; i < _rs.size(); i++) {
							// 这里要判断是否已经插入，是跳出，不是继续
							kaopuIncludeBlog _kaopuIncludeBlog = new kaopuIncludeBlog();
							// 增加记录
							_kaopuIncludeBlog = (kaopuIncludeBlog) _rs.get(i);
							List _a = findByHql(" from kaopuIncludeBlog  t where  t.thekey like '"
									+ _kaopuIncludeBlog.getThekey() + "' ");

							if (_a != null) {
								// 记录已经存在了，跳过
								if (_a.size() > 0) {

								} else {
									_kaopuIncludeBlog.setUid(uid);
									__re = __re + 1;
									// -------------------
									save(_kaopuIncludeBlog);

								}
							}
						}
					}
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
		} catch (IllegalArgumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (FeedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return __re;

	}
}
